﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Text;
using T.ServiceComponent.Error;

namespace T.FAS.Runtime.Metadata.Entity.ScheduleJob
{
    /// <summary>
    /// ScheduleJob异常
    /// </summary>
    [Serializable]
    public class ScheduleJob : IMetaDataContent
    {
        /// <summary>
        /// 计划任务ID
        /// </summary>
        public string ID { get; set; }
        /// <summary>
        /// 计划任务Code
        /// </summary>
        public string Code { get; set; }
        /// <summary>
        /// 计划任务名称
        /// </summary>
        public string Name { get; set; }
        /// <summary>
        /// 描述信息
        /// </summary>
        public string Description { get; set; }
        /// <summary>
        /// 计划任务分组
        /// </summary>
        public string ScheduleGroup { get; set; }
        /// <summary>
        /// 业务类型，部署相关
        /// </summary>
        public string BusinessType { get; set; }
        /// <summary>
        /// 任务类型
        /// </summary>
        public JobType JobType { get; set; }
        /// <summary>
        /// 是否需要持久化，默认需要
        /// </summary>
        public bool IsPersistent { get; set; }
        /// <summary>
        /// 是否在应用Crash后自动启动执行任务
        /// </summary>
        public bool IsAutoRecovery { get; set; }
        /// <summary>
        /// 是否支持并行执行，默认不支持
        /// </summary>
        public bool IsAllowConcurrentExecution { get; set; }
        /// <summary>
        /// 关联元数据ID
        /// </summary>
        public string RelatedMetaDataID { get; set; }
        /// <summary>
        /// 关联元数据Code
        /// </summary>
        public string RelatedMetaDataCode { get; set; }
        /// <summary>
        /// 任务动作详情，比如JS脚本信息
        /// </summary>
        public string JobContent { get; set; }
        /// <summary>
        /// 是否禁用
        /// </summary>
        public bool IsDisabled { get; set; }
        /// <summary>
        /// 是否系统默认，系统默认的不允许用户编辑
        /// </summary>
        public bool IsSysDefault { get; set; }
        /// <summary>
        /// 是否启用日志记录
        /// </summary>
        public bool EnableLog { get; set; }
        /// <summary>
        /// 是否启用监控
        /// </summary>
        public bool EnableMonitor { get; set; }
        /// <summary>
        /// 失败处理策略
        /// </summary>
        public FailureStrategy FailureStrategy { get; set; }
        /// <summary>
        /// 失败重试次数
        /// </summary>
        public int RepeatCount { get; set; }
        /// <summary>
        /// 重试时间间隔 单位秒
        /// </summary>
        public int RepeatInterval { get; set; }
        /// <summary>
        /// 参数信息
        /// </summary>
        public List<ScheduleJobData> ScheduleJobDatas { get; set; }
        /// <summary>
        /// 计划任务用到的触发器信息
        /// </summary>
        public ScheduleTrigger ScheduleTrigger { get; set; }
        /// <summary>
        /// 租户ID
        /// </summary>
        public string TenantID { get; set; }
        /// <summary>
        /// 扩展字段1
        /// </summary>
        public string Ext1 { get; set; }
        /// <summary>
        /// 扩展字段2
        /// </summary>
        public string Ext2 { get; set; }
        /// <summary>
        /// 扩展字段3
        /// </summary>  
        public string Ext3 { get; set; }

        #region 统一元数据参数
        public string MetaDataID { get; set; }
        public string MetaDataCode { get; set; }
        public string MetaDataName { get; set; }
        public DateTime CreateTime { get; set; }
        public string Creator { get; set; }
        public DateTime LastModifyTime { get; set; }
        public string LastModifier { get; set; }
        [JsonIgnore]
        public IMetaData MetaData { get; set; }
        //public Version CurrentVersion { get; set; }
        //public Version CompatibleMinVersion { get; set; }
        //public Version EngineVersion { get; set; }
        public string ProjectBranchID { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;

        public object Clone()
        {
            var newObject = this.MemberwiseClone() as ScheduleJob;

            return newObject;
        }

        #endregion
    }
}
